package com.fifth.apartment.controller;

import com.fifth.apartment.entity.Administrators;
import com.fifth.apartment.entity.Housekeeper;
import com.fifth.apartment.entity.Login;
import com.fifth.apartment.result.Result;
import com.fifth.apartment.service.ManagerLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * TODO
 *
 * @author Dao
 * @since 2024/7/12
 */
@RestController
@RequestMapping("/admin/manager")
@Api(tags = "管理员管家登录接口")
@Slf4j
public class ManagerLoginController {

    @Autowired
    private ManagerLoginService service;

    @ApiOperation("管理员登录接口")
    @PostMapping("administratorsLogin")
    public Result administratorsLogin(@RequestBody Login login){

        try {
            String pwd = service.administratorsLogin(login);
            if (login.getPassword().equals(pwd)){
                return new Result(true,"登陆成功");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return new Result(false,"登陆失败");
    }

    @ApiModelProperty("管家登录接口")
    @PostMapping("housekeeperLogin")
    public Result housekeeperLogin(@RequestBody Login login){

        try {
            String  pwd = service.housekeeperLogin(login);
            if (login.getPassword().equals(pwd)){
                return new Result(true,"登陆成功");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return new Result(false,"登陆失败");
    }
}
